/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.DAO;

import com.Entity.EmployeeProjects;
import com.Interface.EmployeeProjectsInterface;
import java.util.List;
import javax.ejb.Stateful;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author Vi
 */
@Stateless
public class EmployeeProjectsDAO implements EmployeeProjectsInterface{
    
    private EntityManager entityManager;

    public EmployeeProjectsDAO() {
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("persistenceUnit");
        entityManager = factory.createEntityManager();
    }

    @Override
    public List<EmployeeProjects> getCurrentProjects(int idEmployee) {
        return (List<EmployeeProjects>)entityManager.createQuery( "select ep from EmployeeProjects ep where ep.idEmployee = " + idEmployee + " and ep.endDate is null" ).getResultList();
    }

    @Override
    public List<EmployeeProjects> getManagingProjects(int idEmployee) {
        return (List<EmployeeProjects>)entityManager.createQuery( "select ep from EmployeeProjects ep where ep.idEmployee = " + idEmployee + " and ep.isBoss = true" ).getResultList();
    }
}
